package com.example.administrator.baseadapter.recyclerview;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.example.administrator.baseadapter.recyclerview.holder.RecyclerViewHolder;

import java.util.List;

/**
 * Created by baron
 * Date : 2016/5/31 0031 18:29
 * Email: 5267621@qq.com
 */
public abstract class QuickAdapter<T> extends RecyclerView.Adapter<RecyclerViewHolder> {
    protected Context mContext;
    protected int mLayoutId;
    protected List<T> mDatas;
    protected LayoutInflater mInflater;

    public QuickAdapter(Context context, List<T> datas, int layoutId) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mLayoutId = layoutId;
        mDatas = datas;
    }

    public abstract void convert(RecyclerViewHolder holder, T t, int position);

    @Override
    public RecyclerViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
        return RecyclerViewHolder.getViewHolder(mContext, null, parent, mLayoutId, viewType);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder viewHolder, int position) {
        convert(viewHolder, mDatas.get(position), position);
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }
}
